// pages/opt_user_admin/opt_page/produce/inspecting/inspecting.js
var app = getApp()
var BLELocker = require('../../../../../../common/BLELocker.js')

//常量数据配置
var ConstantData = require('../../../../../../common/constant_data.js')
var statistic = require("../../../../../../pages/index/statistic.js")
var util = require("../../../../../../utils/util.js")


Page({

  /**
   * 页面的初始数据
   */
  data: {
    _Data95: '',
    _Data85: '',
    _Data1301: null,
    Data1301: null,
    step: 1,
    step_1_ok: null,
    step_2_ok: null,
    step_3_ok: null,
    step3_ok: true,
    sureZhanshi:false,
    connectStatus: 'connecting',
    motorRunningTime: 6,
    lockMotorRunningTime: 10,
    lastDriVersion: '200305,200314,200820',
    minElectrict: 6000,
    maxElectricity: 7000,
    blueConTime: 0,
    lightOk: 'ok',
    radioOk: 'ok',
    doubleLightOk: 'ok',
    btnOk: 'ok',
    blueToothLightOk: 'ok',
    soundOk: 'ok',
    ligOk: 'ok',
    trumpetOk: 'ok',
    boxType: '',
    boolTypes: [{
      name: '是',
      value: 'ok'
    }, {
      name: '否',
      value: 'nok'
    }],
    booTypes: [{
      name: '是',
      value: 'ok'
    }, {
      name: '否',
      value: 'nok'
    }],
    RSSI: 0,
    rssi: '',
    sim: '',
    maxRs: '',
    minRs: '',
    state: '',
    cardNumber: '',
    showStep4: true, //展示刷卡页面
    toStepFour: false, //网络连接成功去第四部
    contuines: true, // 一直加载网络状态
    time: '',
    canUseRssi:true,
    errInfo: null,
    hasJurisdiction:true,
    proTestType: 1, //测试类型
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('options', options);
    let that = this;
    that.setData({
      mac: options.mac,
      deviceId: decodeURIComponent(options.deviceId),
      curBlueName: 'DK' + options.mac,
      producer_num: options.producer_num,
      producer_name: options.producer_name,
      testId: options.testId,
      hid: options.hid,
      boxType: options.boxType,
      proTestType: options.proTestType,
      isNBtestType: options.proTestType == 2,//是否未NB锁具测试，如链条锁，NB短钩
      lockVer: options.lockVer ? options.lockVer : '',
      lockFullVersion: options.lockFullVersion ? options.lockFullVersion : null,
      lockMaxElectricity: options.lockMaxElectricity ? options.lockMaxElectricity : '',
      lockMinElectricity: options.lockMinElectricity ? options.lockMinElectricity : '',
    })
    wx.setStorageSync('boxType', that.data.boxType)
    wx.setNavigationBarTitle({
      title: that.data.deviceId + '检测中',
    })
    //获取最新驱动版本
    let lastDriVersion = wx.getStorageSync('lastDriVersion')
    let minElectrict = wx.getStorageSync('minElectrict')
    let maxElectricity = wx.getStorageSync('maxElectricity')
    let motorRunningTime = wx.getStorageSync('motorRunningTime')
    let lockMotorRunningTime = wx.getStorageSync('lockMotorRunningTime')
    let RSSIMax = wx.getStorageSync('RSSIMax')
    let RSSIMin = wx.getStorageSync('RSSIMin')
    let hasJurisdiction = wx.getStorageSync('hasJurisdiction')
    let firmEquType = getApp().globalData.firmEquType;
    //是否是链条锁
    let isLinkLock = firmEquType == "BB";
    that.setData({
      isLinkLock: isLinkLock,
      lastDriVersion: lastDriVersion,
      minElectrict: minElectrict,
      maxElectricity: maxElectricity,
      motorRunningTime: motorRunningTime,
      lockMotorRunningTime: lockMotorRunningTime,
      RSSIMax: RSSIMax,
      RSSIMin: RSSIMin,
      hasJurisdiction:hasJurisdiction
    })
    console.log(that.data.hasJurisdiction,that.data.lastDriVersion, that.data.minElectrict, that.data.maxElectricity, that.data.motorRunningTime, '获取最新驱动测试')
    // if(!that.data.lastDriVersion||!that.data.minElectrict||!that.data.maxElectricity||!that.data.motorRunningTime){
    //   that.getLastDriVersion();
    // }
    that.connectBLEDevice();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    //断开蓝牙连接
    BLELocker.disconnect('produce99');
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 重试连接
   */
  retryConnect() {
    console.log('retryConnect');
    this.setData({
      _Data85: '',
      _Data95: '',
      connectStatus: 'connecting'
    })
    this.connectBLEDevice();
  },

  /**
   * 指示灯是否常亮
   */
  lightChange(e) {
    let that = this;
    that.setData({
      lightOk: e.detail.value,
    })
    if (that.data.lightOk == 'nok') {
      if (!that.data.errReason) {
        that.data.errReason = {};
      }
      that.data.errReason.light_err = 'no_light';
    }
  },

  /**
   * 蜂鸣器是否有声音
   */
  soundChange(e) {
    console.log('soundChange', e);
    let that = this;
    that.setData({
      soundOk: e.detail.value
    })
    if (that.data.soundOk == 'nok') {
      if (!that.data.errReason) {
        that.data.errReason = {};
      }
      that.data.errReason.sound_err = 'no_sound';
    }
  },
  /**
   * 语音芯片是否发音：
   */
  radioChange(e) {
    console.log(e.detail.value)
    let that = this;
    that.setData({
      radioOk: e.detail.value,
    })
    if (that.data.radioOk == 'nok') {
      if (!that.data.errInfo) {
        that.data.errInfo = {};
      }
      that.data.errInfo.radio_err = 'no_radio';
    }
  },
  /**
   * 按键双色LED是否红绿灯循环闪烁：
   */
  doubleLightChange(e) {
    console.log(e.detail.value)
    let that = this;
    that.setData({
      doubleLightOk: e.detail.value,
    })
    if (that.data.doubleLightOk == 'nok') {
      if (!that.data.errInfo) {
        that.data.errInfo = {};
      }
      that.data.errInfo.doubleLight_err = 'no_doubleLight';
    }
  },
  /**
   * 按键是否正常
   */
  btnChange(e) {
    console.log(e.detail.value)
    let that = this;
    that.setData({
      btnOk: e.detail.value,
    })
    if (that.data.btnOk == 'nok') {
      if (!that.data.errInfo) {
        that.data.errInfo = {};
      }
      that.data.errInfo.btn_err = 'no_btn';
    }
  },
  /**
   * 蓝牙灯是否正常闪烁：
   */
  blueToothLightChange(e) {
    console.log(e.detail.value)
    let that = this;
    that.setData({
      blueToothLightOk: e.detail.value,
    })
    if (that.data.blueToothLightOk == 'nok') {
      if (!that.data.errInfo) {
        that.data.errInfo = {};
      }
      that.data.errInfo.blueToothLight_err = 'no_blueToothLight';
    }
  },
  // 喇叭
  trumpetChange(e) {
    let that = this;
    that.setData({
      trumpetOk: e.detail.value,
    })
    if (that.data.trumpetOk == 'nok') {
      if (!that.data.errReason) {
        that.data.errReason = {};
      }
      that.data.errReason.light_err = 'no_trumpet';
    }
  },
  // 按键灯
  ligChange(e) {
    let that = this;
    that.setData({
      ligOk: e.detail.value,
    })
    if (that.data.ligOk == 'nok') {
      if (!that.data.errReason) {
        that.data.errReason = {};
      }
      that.data.errReason.light_err = 'no_lig';
    }
  },
  /**
   * 获取最新驱动版本
   */
  getLastDriVersion() {
    let that = this;
    app.executeRequest(function (header) {
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_admin/produce/produce_testing',
        header: header,
        success: function (res) {
          console.log("low sign a", res);
          if (res.data.result === 0 && res.data.data) {
            that.setData({
              lastDriVersion: res.data.data.ver,
              minElectrict: res.data.data.min_electricity,
              maxElectricity: res.data.data.max_electricity,
              motorRunningTime: res.data.data.motorRunningTime,
              lockMotorRunningTime: res.data.data.lockMotorRunningTime,
              RSSIMax: res.data.data.blueSignalStrength.max,
              RSSIMin: res.data.data.blueSignalStrength.min,
              hasJurisdiction:res.data.data.hasJurisdiction
            })
            wx.setStorageSync('lastDriVersion', res.data.data.ver);
            wx.setStorageSync('minElectrict', res.data.data.min_electricity);
            wx.setStorageSync('maxElectricity', res.data.data.max_electricity);
            wx.setStorageSync('motorRunningTime', res.data.data.motorRunningTime);
            wx.setStorageSync('lockMotorRunningTime', res.data.data.lockMotorRunningTime);
          }
        }
      })
    });
  },

  /**
   * 点击确定关闭提示框
   */
  tipBtnClick: function () {
    this.setData({
      tipStatus: false,
    });
  },

  goBack: function () {
    wx.navigateBack({
      delta: 1
    })
  },

  /**
   * 检测不通过，提交检测结果
   */
  complete: function () {
    let that = this;
    that.setData({
      contuines: false
    })
    if (that.data.step == 2) {
      if (!that.data.lightOk) {
        wx.showToast({
          title: '选择指示灯状态',
          icon: 'none'
        })
        return;
      } else if (!that.data.soundOk) {
        wx.showToast({
          title: '选择蜂鸣器状态',
          icon: 'none'
        })
        return;
      }
    }
    if (that.data.step == 4) {
      if (!that.data.trumpetOk) {
        wx.showToast({
          title: '选择喇叭状态',
          icon: 'none'
        })
        return;
      } else if (!that.data.ligOk) {
        wx.showToast({
          title: '选择按键灯状态',
          icon: 'none'
        })
        return;
      }
    }
    wx.showLoading({
      title: '正在提交检测',
      mask: true
    })
    let blueConTime = (that.data.endTime_95 - that.data.startTime_95) / 1000;
    let errReason = that.data.errReason ? that.data.errReason : null;
    if (that.data.connectStatus == 'connectFail') {
      if (!errReason) {
        that.data.errReason = {};
        errReason = that.data.errReason;
      }
      errReason.blue_no_con = 'err_no_con';
    }
    if (that.data.cmd85Status) {
      if (!errReason) {
        that.data.errReason = {};
        errReason = that.data.errReason;
      }
      errReason.blue_85_status = that.data.cmd85Status;
    }
    blueConTime = blueConTime > 0 ? blueConTime : 0;
    app.executeRequest(function (header) {
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_admin/produce/produce_test_record',
        header: header,
        data: {
          step: that.data.step,
          produceTestId: parseInt(that.data.testId),
          errReason: JSON.stringify(errReason),
          pileVer: that.data.boxType,
          blueConTime: blueConTime,
          mac: that.data.mac
        },
        success: function (res) {
          getApp().hideLoading();
          if (res.data.result == 0) {
            if (!errReason) {
              wx.showToast({
                title: '检测通过',
                duration: 3000
              })
              setTimeout(() => {
                wx.navigateBack({
                  delta: 1
                })
              }, 3000);
            } else {
              wx.showToast({
                title: '不通过,已提交',
                icon: 'none'
              })
              that.setData({
                confirmOnly: true
              })
            }
          } else {
            wx.showToast({
              title: 'rst:网络异常',
              icon: 'none'
            })
          }
        },
        fail: function () {
          getApp().hideLoading();
          wx.showToast({
            title: 'fail:网络异常',
            icon: 'none'
          })
        },
        complete: function () {
          //断开蓝牙连接
          BLELocker.disconnect('produce303');
        }
      })
    });
  },

  /**
   * 静默提交
   */
  completeSilent: function () {
    let that = this;

    let blueConTime = (that.data.endTime_95 - that.data.startTime_95) / 1000;
    let errReason = that.data.errReason ? that.data.errReason : null;
    if (that.data.connectStatus == 'connectFail') {
      if (!errReason) {
        that.data.errReason = {};
        errReason = that.data.errReason;
      }
      errReason.blue_no_con = 'err_no_con';
    }
    if (that.data.cmd85Status) {
      if (!errReason) {
        that.data.errReason = {};
        errReason = that.data.errReason;
      }
      errReason.blue_85_status = that.data.cmd85Status;
    }

    if (that.data.soundOk == 'nok') {
      if (!that.data.errReason) {
        that.data.errReason = {};
      }
      that.data.errReason.sound_err = 'no_sound';
    }

    if (that.data.lightOk == 'nok') {
      if (!that.data.errReason) {
        that.data.errReason = {};
      }
      that.data.errReason.light_err = 'no_light';
    }
    blueConTime = blueConTime > 0 ? blueConTime : 0;
    app.executeRequest(function (header) {
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_admin/produce/produce_test_record',
        header: header,
        data: {
          step: that.data.step,
          produceTestId: parseInt(that.data.testId),
          errReason: JSON.stringify(errReason),
          pileVer: that.data.boxType,
          blueConTime: blueConTime,
          mac: that.data.mac

        },
        success: function (res) {
          let netErr = app.handleRes(res, that);
          if (netErr) {
            return
          }
        },
        fail: function () {}
      })
    });
  },

  /**
   * 完成第二步马达空转检测，插入锁扣进行第三步检测
   */
  toStep3: function () {
    let that = this;
    that.setData({
      errI: 0,
      step: 3,
      _Data95: '',
      _Data85: '',
      errReason: null,
      connectStatus: 'connecting'
    })
    that.connectBLEDevice();
  },
  countRped() {
    this.toStep4()
  },
  toStep4: function () {
    let that = this;
    that.setData({
      step: 4,
      state: 'connecting'
    })
    app.executeRequest(function (header) {
      wx.showLoading({
        title: '连接中',
      })
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_admin/produce/get_nb_connect_info',
        header: header,
        data: {
          mac: that.data.mac,
        },
        success: function (res) {
          getApp().hideLoading()
          console.log("lowasss", res);
          if (res.data.result === 0) {
            if (res.data.data.connectStat == '' && that.data.contuines) {
              wx.showToast({
                title: '请尝试重连',
              })
              // that.toStep4()
            } else if (res.data.data.connectStat == "failure") {
              that.setData({
                // toStepFour:true,
                state: '连接失败'
              })
            } else if (res.data.data.connectStat == "success") {
              that.setData({
                toStepFour: true,
                state: '连接成功'
              });
              // that.submitBtn()
              var time = setInterval(() => {
                app.executeRequest(function (header) {
                  wx.request({
                    url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_admin/produce/get_iccard_info',
                    header: header,
                    data: {
                      mac: that.data.mac,
                    },
                    success: function (res) {
                      if (res.data.data.cardNumber) {
                        clearInterval(that.data.time)
                        that.submitBtn()
                      }
                    },
                    fail(res) {
                      wx.showToast({
                        title: res.description,
                      })
                    }
                  })
                })
              }, 1000)
              that.setData({
                time: time
              })
            }
          }
        }
      })
    });

  },
  /**
   * 连接蓝牙设备
   */
  connectBLEDevice: function () {
    getApp().globalData.isAllowBroadcastBack = 0;
    wx.showLoading({
      title: '开始连接...',
      mask: true
    });

    let that = this;
    that.data.startTime_95 = new Date();
    that.setData({
      connectStatus: 'connecting'
    })
    if (that.data.step == 3) {
      that.setData({
        _Data85: '',
        _Data95: ''
      })
    }
    //使用新的连接
    BLELocker.newConnect(that.data.curBlueName, function (status, data) {
      console.log(status, data, 'status, data')
      that.handleStatus(status, data)
      if (app.globalData.BLEdeviceId) {
        if (wx.getBLEDeviceRSSI) {
          wx.getBLEDeviceRSSI({
            deviceId: app.globalData.BLEdeviceId,
            success(res) {
              console.log(res.RSSI)
              that.setData({
                RSSI: res.RSSI,
                canUseRssi:true
              })
              console.log('我正在获取RSSI，res')
            }
          })
        } else {
          that.setData({
            canUseRssi:false
          })
          // 如果希望用户在最新版本的客户端上体验您的小程序，可以这样子提示
          // wx.showModal({
          //   title: '提示',
          //   content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
          // })
          // wx.showToast({
          //   title: '微信版本过低',
          // })
        }

      }
    }, 0, false, null, null, that);
  },

  /**
   * 处理设备连接状态变化回调
   */
  handleStatus: function (status, data) {
    let that = this
    console.log('handleStatus-->', status, data);
    if (status == BLELocker.Status.bleScanStart) {
      console.log('执行了这个AA')
      getApp().hideLoading();
      wx.showLoading({
        title: '搜索蓝牙...',
        mask: true
      })
    } else if (status == BLELocker.Status.appVersionNotSupported) {
      console.log('执行了这个AB')
      getApp().hideLoading();
      wx.showToast({
        title: '微信版本低',
        icon: 'none'
      })
      that.setData({
        connectStatus: 'connectFail',
        step_1_ok: false,
        _Data95: null
      })
    } else if (status == BLELocker.Status.bleIsClosed || status == BLELocker.Status.adaperOpenFail) {
      console.log('执行了这个A')
      getApp().hideLoading();
      wx.showToast({
        title: '请打开蓝牙',
        icon: 'none',
        duration: 2500,
      })
      that.setData({
        connectStatus: 'connectFail',
        step_1_ok: false,
        _Data95: null
      })
    } else if (status == BLELocker.Status.bleNotSupportWXService || status == BLELocker.Status.bleNotSupportWXCharacteristic) {
      console.log('执行了这个B')
      getApp().hideLoading();
      wx.showToast({
        title: '系统版本低',
        icon: 'none'
      })
      that.setData({
        connectStatus: 'connectFail',
        step_1_ok: false,
        _Data95: null
      })
    } else if (status == BLELocker.Status.bleReceiveAuthData) {
      console.log('执行了这个C')
      getApp().hideLoading();
      wx.showLoading({
        title: '读取数据....',
        icon: 'none',
        mask: true
      })
    } else if (status == BLELocker.Status.bleConnectTimeout) {
      console.log('执行了这个D')
      getApp().hideLoading()
      //断开蓝牙连接
      BLELocker.disconnect('produce464');
      wx.showToast({
        title: '连接超时',
        icon: 'none'
      })
      that.setData({
        connectStatus: 'connectFail',
        step_1_ok: false,
        _Data95: null
      })
      that.completeSilent();

    } else if (status == BLELocker.Status.bleClosed) {
      console.log('执行了这个E')
      getApp().hideLoading()
      wx.showToast({
        title: '蓝牙已关闭',
        icon: 'none'
      })
      that.setData({
        connectStatus: 'connectFail',
        step_1_ok: false,
        _Data95: null
      })
    } else if (status == BLELocker.Status.bleOpened) {
      console.log('执行了这个F')

      //这里不需要做任何处理

    } else if (status == BLELocker.Status.bleSend85Timeout || status == BLELocker.Status.ble85Back1Timeout || status == BLELocker.Status.ble85Back2Timeout) {
      console.log('执行了这个G')
      getApp().hideLoading()
      wx.showToast({
        title: '开锁超时',
        icon: 'none'
      })

      that.setData({
        _Data85: null,
        cmd85Status: '超时',
      })
      that.completeSilent();
      if (that.data.step == 1) {
        that.setData({
          step_1_ok: false,
        })
      } else if (that.data.step == 2) {
        that.setData({
          step_2_ok: false,
        })
      } else if (that.data.step == 3) {
        that.setData({
          step_3_ok: false,
        })
      } else if (that.data.step == 4) {
        that.setData({
          step_4_ok: false,
        })
      }
    } else if (status == BLELocker.Status.bleSend95Timeout) {
      console.log('执行了这个H')
      getApp().hideLoading()
      wx.showToast({
        title: '95超时',
        icon: 'none'
      })
      BLELocker.disconnect('produce522');
      that.setData({
        connectStatus: 'connectFail',
        step_1_ok: false,
        _Data95: null
      })
      that.completeSilent();

    } else if (status == BLELocker.Status.ble85Data || status == BLELocker.Status.ble88Data) {
      console.log('执行了这个II')
      console.log(that.data.step, '打印这个STEP')
      if (data == null) {
        getApp().hideLoading()
        wx.showToast({
          title: '开锁失败',
          icon: 'none'
        })
        that.setData({
          _Data85: null,
          cmd85Status: '回执null',
        })
        that.completeSilent();
        if (that.data.step == 1) {
          that.setData({
            step_1_ok: false,
          })
        } else if (that.data.step == 2) {
          that.setData({
            step_2_ok: false,
          })
        } else if (that.data.step == 3) {
          that.setData({
            step_3_ok: false,
          })
        } else if (that.data.step == 4) {
          that.setData({
            step_4_ok: false,
          })
        }

      } else {
        //上传85数据
        statistic.statisticData('85data', JSON.stringify(data));
        if (data.backSeq == 2) {
          getApp().hideLoading()
          that.setData({
            _Data85: data,
            cmd85Status: ''
          })
          let i = 0;
          let retryEject = data.retryEject; //马达重试标记
          let lockErrCode = data.lockErrCode; //开锁错误码。0：正常弹出，滴滴滴3声；1：锁钩开关正常，插入开关错误，滴滴滴5声；2：锁钩开关错误，插入开关正确，滴滴滴4声
          let noEject = data.noEject; //未弹出标记
          let insertStat = data.insertStat;
          let lockStat = data.lockStat;
          let motorRunningTime = parseInt(data.motorRunningTime, 16);
          let errReason = that.data.errReason == null ? {} : that.data.errReason;
          if (that.data.step == 1) {
            that.setData({
              _Data85: '',
              _Data95: '',
              connectStatus: 'connecting'
            })
            that.connectBLEDevice();
            return;
          } else if (that.data.step == 2) {
            console.log(motorRunningTime, that.data.motorRunningTime, 'motorRunningTime')
            if (that.data.isNBtestType) {
              if (motorRunningTime > that.data.lockMotorRunningTime || motorRunningTime == that.data.lockMotorRunningTime) { //马达转动多次
                errReason.motor_times = parseInt(data.motorRunningTime, 16) + '';
                i++;
              }
            } else {
              if (motorRunningTime > that.data.motorRunningTime || motorRunningTime == that.data.motorRunningTime) { //马达转动多次
                errReason.motor_times = parseInt(data.motorRunningTime, 16) + '';
                i++;
              }
            }
            if (that.data.isNBtestType) {} else {
              if (lockErrCode != '40') { //没有滴滴滴3声
                errReason.didi_three_stat = 'no_three_didi';
                i++;
              }
            }
            if (lockStat != 0) {
              errReason.hook_err_after = parseInt(lockStat, 16) + '';
              i++;
            }
            if (insertStat != 0) {
              errReason.insert_err_after = parseInt(insertStat, 16) + '';
              i++;
            }
            if (i != 0) {
              that.setData({
                step_2_ok: false,
              });
              that.data.errReason = errReason;
              that.completeSilent();
            } else {
              that.setData({
                step_2_ok: true,
              })
              that.data.errReason = null;
              console.log('执行静默提交')
              that.completeSilent();
            }
          } else if (that.data.step == 3) {
            console.log('errI--3-->', that.data.errI);
            if (that.data.isNBtestType) {
              if (motorRunningTime > that.data.lockMotorRunningTime || motorRunningTime == that.data.lockMotorRunningTime) { //马达转动多次
                errReason.motor_times = parseInt(data.motorRunningTime, 16) + '';
                i++;
              }
            } else {
              if (motorRunningTime > that.data.motorRunningTime || motorRunningTime == that.data.motorRunningTime) { //马达转动多次
                errReason.motor_times = parseInt(data.motorRunningTime, 16) + '';
                that.data.errI++;
              }
            }
            if (that.data.isNBtestType) {

            } else {
              if (lockErrCode != '40') { //滴滴滴3声
                errReason.didi_three_stat = 'no_three_didi';
                that.data.errI++;
              }
            }

            if (lockStat != 0) {
              errReason.hook_err_after = parseInt(lockStat, 16) + '';
              that.data.errI++;
            }
            if (insertStat != 0) {
              errReason.insert_err_after = parseInt(insertStat, 16) + '';
              that.data.errI++;
            }
            if (that.data.errI != 0) {
              that.setData({
                step_3_ok: false,
              });
              that.data.errReason = errReason;
              that.complete();
            } else {
              that.setData({
                step_3_ok: true,
              })
              that.data.errReason = null;
              that.complete();
            }
          } else if (that.data.step == 4) {
            console.log('errI--4-->', that.data.errI);
            if(that.data.canUseRssi){
              if (that.data.rssi == '' || (that.data.rssi < that.data.minRs && that.data.rssi > that.data.maxRs)) {
                errReason.rssi_no_err = that.data.rssi + '不在范围值';
                that.data.errI++;
              }
            }
            if (that.data.sim == '') {
              errReason.sim_stat_err = parseInt(that.data.sim, 16) + '';
              that.data.errI++;
            }
            if (that.data.cardNumber == '') {
              errReason.card_err = parseInt(that.data.cardNumber, 16) + '';
              that.data.errI++;
            }
            if (that.data.errI != 0) {
              that.setData({
                step_4_ok: false,
              });
              that.data.errReason = errReason;
              that.complete();
            } else {
              that.setData({
                step_4_ok: true,
              })
              that.data.errReason = null;
              that.complete();
            }
          }
        }

      }
    } else if (status == BLELocker.Status.ble95Data) {
      console.log('执行了这个J', app.globalData.BLEdeviceId)
      getApp().hideLoading()
      wx.removeStorageSync('retryConCounts');
      app.globalData.conIsSuc = true;
      if (app.globalData.conTimeoutTimer) {
        clearTimeout(app.globalData.conTimeoutTimer);
      }
      if (app.globalData.data95ReceiveTimer) {
        clearTimeout(app.globalData.data95ReceiveTimer);
      }
      if (app.globalData.directConnectTimer) {
        clearTimeout(app.globalData.directConnectTimer);
      }
      if (app.globalData.auto95RecTimer) {
        clearTimeout(app.globalData.auto95RecTimer);
      }
      that.data.endTime_95 = new Date();
      if (data == null) {
        wx.showToast({
          title: '连接失败',
          icon: 'none'
        })
        that.setData({
          connectStatus: 'connectFail',
          _Data95: null,
        })
        that.completeSilent();
        if (that.data.step == 1) {
          that.setData({
            step_1_ok: false,
          })
        } else if (that.data.step == 2) {
          that.setData({
            step_2_ok: false,
          })
        } else if (that.data.step == 3) {
          that.setData({
            step_3_ok: false,
          })
        } else if (that.data.step == 4) {
          that.setData({
            step_4_ok: false,
          })
        }
      } else {
        wx.showToast({
          title: '连接成功',
          icon: 'none'
        })
        that.setData({
          connectStatus: 'connectSuc',
          _Data95: data
        })
        console.log(data, 'data95数据')
        //上传95数据
        statistic.statisticData('95data', JSON.stringify(data));
        let i = 0;
        let electrict = data.electrict;
        let minElectrict = that.data.minElectrict;
        let maxElectricity = that.data.maxElectricity;
        let hookStatus = data.hookStatus;
        let chairSwitchSatus = data.chairSwitchSatus;
        let didi = data.programRestartTimes;
        let rfid = data.rfid;
        let version = data.pile_ver;
        let errReason = {};
        if (that.data.step == 1) {
          if (rfid != 'FFFFFFFF') {
            that.send85Command();
            return;
          }
          if (that.data.isNBtestType) {
            console.log('链条锁控制盒V1lockMinElectricity:', that.data.lockMinElectricity, that.data.lockMaxElectricity)
            if (electrict < that.data.lockMinElectricity || electrict > that.data.lockMaxElectricity) {
              errReason.electric_err = electrict + '';
              i++;
            }
          } else {
            if (electrict < minElectrict || electrict > maxElectricity) {
              errReason.electric_err = electrict + '';
              i++;
            }
          }
          if(that.data.lockFullVersion) { // mark: 控制盒版本校验            
            let curFullVer = data.softwareVersion + version;
            that.setData({
                curFullVer: curFullVer,
                curVerType: data.softwareVersion,
                lastVerType: that.data.lockFullVersion.substring(0, 10),
            })
            
            //B031A3CC50220717 BB23A7CC50220717
            let curVerPre = that.data.curVerType.substring(0,2) + that.data.curVerType.substring(4)
            let lastVerPre = that.data.lastVerType.substring(0,2) + that.data.lastVerType.substring(4)
            console.log("控制盒版本校验-->", curFullVer, that.data.lockFullVersion, curVerPre, lastVerPre)
            if (curVerPre != lastVerPre || parseInt(version) < parseInt(that.data.lockVer)) {
                errReason.version_err = version + '';
                i++;
            } 
          }else if (that.data.isNBtestType) {
            console.log('链条锁控制盒V1lockVer:', that.data.lockVer, version)
            console.log('链条锁控制盒V1lockVer:', parseInt(version) >= parseInt(that.data.lockVer))
            if (parseInt(version) < parseInt(that.data.lockVer)) {
              errReason.version_err = version + '';
              i++;
            } 
          } else {
            console.log(that.data.lastDriVersion,version,'我是控制盒版本')
            if (parseInt(version) < parseInt(that.data.lastDriVersion)) {
              errReason.version_err = version + '';
              i++;
            }
          }

          if (hookStatus == 1 && !that.data.isNBtestType) {
            errReason.hook_err = parseInt(hookStatus, 16) + '';
            i++;
          }
          if (chairSwitchSatus == 1 && !that.data.isNBtestType) {
            errReason.insert_err = parseInt(chairSwitchSatus, 16) + '';
            i++;
          }
          if(that.data.canUseRssi){
            if (that.data.RSSI > that.data.RSSIMax && that.data.RSSI < that.data.RSSIMin) {
              errReason.RSSI_err = that.data.RSSI + '';
              i++;
            }
          }
          console.log(i, errReason, '打印报错')
          if (i != 0) {
            that.setData({
              step_1_ok: false,
            });
            that.data.errReason = errReason;
            if (that.data.isNBtestType) {
              let startErrors = {}
              let blueConTime = (that.data.endTime_95 - that.data.startTime_95) / 1000
              startErrors.step = that.data.step ? that.data.step : '',
                startErrors.produceTestId = parseInt(that.data.testId) ? parseInt(that.data.testId) : '',
                startErrors.errReason = JSON.stringify(errReason) ? JSON.stringify(errReason) : '',
                startErrors.pileVer = that.data.boxType ? that.data.boxType : '',
                startErrors.blueConTime = blueConTime ? blueConTime : '',
                startErrors.mac = that.data.mac ? that.data.mac : ''
              that.setData({
                startError: startErrors
              })
              that.setInformation();
            } else {
              that.complete();
            }
          } else {
            that.setData({
              step_1_ok: true,
              step: 2,
              sureZhanshi:true,
              errReason: null
            })
            if (that.data.isNBtestType) {
              let startErrors = {}
              let blueConTime = (that.data.endTime_95 - that.data.startTime_95) / 1000
              startErrors.step = that.data.step ? that.data.step : '',
                startErrors.produceTestId = parseInt(that.data.testId) ? parseInt(that.data.testId) : '',
                startErrors.errReason = JSON.stringify(errReason) ? JSON.stringify(errReason) : '',
                startErrors.pileVer = that.data.boxType ? that.data.boxType : '',
                startErrors.blueConTime = blueConTime ? blueConTime : '',
                startErrors.mac = that.data.mac ? that.data.mac : ''
              that.setData({
                startError: startErrors
              })
            }
            console.log('马达空转检测')
            wx.showLoading({
              title: '马达空转检测',
              mask: true
            })
            setTimeout(() => {
              if (that.data.isNBtestType) {
                that.send1301Command();
              } else {
                that.send85Command();
              }
            }, 1500)
          }
        } else if (that.data.step == 2) {
          // if(that.data.isNBtestType){
          //   that.send1301Command();
          // }else{
          that.send85Command();
          // }
        } else if (that.data.step == 3) {
          that.data.errI = 0;
          console.log('errI--1-->', that.data.errI);
          if (rfid == 'FFFFFFFF') {
            errReason.rfid_no_err = rfid + '';
            that.data.errI++;
          }
          if (that.data.isNBtestType) {} else {
            if (didi == 0) {
              errReason.didi_stat_err = parseInt(didi, 16) + '';
              that.data.errI++;
            }
          }
          if (hookStatus == 1) {
            errReason.hook_err = parseInt(hookStatus, 16) + '';
            that.data.errI++;
          }
          if (chairSwitchSatus == 0) {
            errReason.insert_err = parseInt(chairSwitchSatus, 16) + '';
            that.data.errI++;
          }
          if (that.data.errI != 0) {
            that.setData({
              step_3_ok: false,
              _Data85: null,
            });
            that.data.errReason = errReason;
            console.log('1拿到95，开始发送85');
            that.send85Command()
          } else {
            that.data.errI = 0;
            console.log('errI--2-->', that.data.errI);
            that.data.errReason = null;
            console.log('2拿到95，开始发送85');
            that.send85Command()
          }
        } else if (that.data.step == 4) {
          that.data.errI = 0;
          if(that.data.canUseRssi){
            if (!that.data.rssi || (that.data.rssi < that.data.minRs && that.data.rssi > that.data.maxRs)) {
              errReason.rssi_no_err = that.data.rssi + '';
              that.data.errI++;
            }
          }
          if (!that.data.sim) {
            errReason.sim_stat_err = parseInt(that.data.sim, 16) + '';
            that.data.errI++;
          }
          console.log(that.data.cardNumber, '打印cardNumber')
          if (!that.data.cardNumber) {
            errReason.card_err = parseInt(that.data.cardNumber, 16) + '';
            that.data.errI++;
          }
          if (that.data.errI != 0) {
            that.setData({
              step_4_ok: false,
            });
            that.data.errReason = errReason;
            console.log('1拿到95，开始发送85');
          } else {
            that.setData({
              step_4_ok: true,
            })
            that.data.errI = 0;
            that.data.errReason = null;
            console.log('2拿到95，开始发送85');
            setTimeout(() => {
              that.complete()
            }, 3000)
          }
        }
      }
    }

  },
  submitBtn() {
    let that = this;
    app.executeRequest(function (header) {
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_admin/produce/get_iccard_info',
        header: header,
        data: {
          mac: that.data.mac,
        },
        success: function (res) {
          let lockRssiStrengh = JSON.parse(res.data.data.lockRssiStrengh)
          that.setData({
            showStep4: false,
            rssi: parseInt(res.data.data.rssi, 16),
            sim: res.data.data.sim,
            cardNumber: res.data.data.cardNumber,
            maxRs: lockRssiStrengh.max,
            minRs: lockRssiStrengh.min,
          })
          console.log(res)
          console.log('我在这儿执行了检测方法')
          that.connectBLEDevice()
        },
        fail(res) {
          wx.showToast({
            title: res.description,
          })
        }
      })
    });
  },
  /***
   * 发送85开锁
   */
  send85Command: function () {
    let that = this;
    wx.showLoading({
      title: '开锁中',
      mask: true
    })
    BLELocker.send85Command(function (isSuccess) {
      if (isSuccess == false) {
        console.log('开锁异常');
        // getApp().hideLoading();
        // wx.showToast({
        //   title: '开锁异常',
        //   icon:'none'
        // })
      } else {

      }
    })

  },
  send1301Command: function () {
    let that = this;
    BLELocker.setParams(function (status, data) {
      console.log('这是回调函数', data, typeof (data))
      var _Data1301 = {}
      var Data1301 = {}
      that.setData({
        sureZhanshi:true
      })
      let firmEquType = getApp().globalData.firmEquType;
      //是否是链条锁
      let isLinkLock = firmEquType == "BB";
      //是否是NB短钩
      let isNbLock = firmEquType == "B0";
      if (data && data.substring(8, 12) == '1301') {
        if(isLinkLock) {         
            _Data1301.a = parseInt(data.substring(10, 12), 16)
            _Data1301.b = parseInt(data.substring(12, 14), 16)
            _Data1301.mac = data.substring(14, 26) // mac
            _Data1301.Version = data.substring(26, 42) //固件版本号
            _Data1301.voltage = parseInt(data.substring(42, 46), 16) // 电池电压采集值 0：正常，其他值：采集电压值（不在设定范围）
            _Data1301.memorizer = parseInt(data.substring(46, 48), 16) //0：正常，1：异常 存储器，测试结果
            _Data1301.runningTime = parseInt(data.substring(48, 50), 16) // 马达运行时长 0：正常
            _Data1301.locking = parseInt(data.substring(50, 52), 16) // 马达开锁错误码 0：正常
            _Data1301.i = parseInt(data.substring(52, 54), 16) // 马达开锁没弹开 0：正常
            _Data1301.j = parseInt(data.substring(54, 56), 16) // 马达重试开锁 0：正常
            _Data1301.insertionSwitch = parseInt(data.substring(56, 58), 16) // 插入开关 0：正常
            _Data1301.lockSwitch = parseInt(data.substring(58, 60), 16) // 锁钩开关 0：正常
            _Data1301.m = parseInt(data.substring(60, 62), 16) // END 0：正常         
        }
        if(isNbLock) {
          _Data1301.a = parseInt(data.substring(10, 12), 16)
          _Data1301.b = parseInt(data.substring(12, 14), 16)
          _Data1301.mac = data.substring(14, 26) // mac
          _Data1301.Version = data.substring(26, 42) //固件版本号
          _Data1301.voltage = parseInt(data.substring(42, 46), 16) // 电池电压采集值 0：正常，其他值：采集电压值（不在设定范围）
          _Data1301.memorizer = parseInt(data.substring(46, 48), 16) //0：正常，1：异常 存储器，测试结果
          _Data1301.runningTime = parseInt(data.substring(48, 50), 16) // 马达运行时长 0：正常
          _Data1301.locking = parseInt(data.substring(50, 52), 16) // 马达开锁错误码 0：正常
          _Data1301.i = parseInt(data.substring(52, 54), 16) // 马达开锁没弹开 0：正常
          _Data1301.j = parseInt(data.substring(54, 56), 16) // 马达重试开锁 0：正常
          _Data1301.insertionSwitch = parseInt(data.substring(56, 58), 16) // 插入开关 0：正常
          _Data1301.lockSwitch = parseInt(data.substring(58, 60), 16) // 锁钩开关 0：正常
          _Data1301.motorPosition = parseInt(data.substring(60, 62), 16) // 马达定位开关 0:正常
          _Data1301.m = parseInt(data.substring(62, 64), 16) // END 0:正常
        }
        that.setData({
          _Data1301: _Data1301
        })
        that.submit()
        console.log(that.data._Data1301, 'that.data._Data1301')
      }
      if (data && data.substring(8, 12) == '1302') {
        Data1301.isLinkLock = isLinkLock
        Data1301.isNbLock = isNbLock
        if(isNbLock) {  
          Data1301.a = parseInt(data.substring(10, 12), 16)
          Data1301.b = parseInt(data.substring(12, 14), 16)
          Data1301.mac = data.substring(14, 26) // mac
          Data1301.KeyTrigger = -1;//不存在此key
          Data1301.insertionSwitched = parseInt(data.substring(26, 28), 16) // 锁扣插入后，插入开关状态是否为1，
          Data1301.lockSwitched = parseInt(data.substring(28, 30), 16) // 锁扣插入后，锁钩状态是否为0
          Data1301.motorPosition = parseInt(data.substring(30, 32), 16) // 马达定位开关 0正常
          Data1301.rfidOne = parseInt(data.substring(32, 34), 16) // RFID_1
          Data1301.runningTime = parseInt(data.substring(34, 36), 16) // 马达运行时长
          Data1301.locking = parseInt(data.substring(36, 38), 16) // 马达开锁错误码
          Data1301.k = parseInt(data.substring(38, 40), 16) // 马达开锁没弹开
          Data1301.l = parseInt(data.substring(40, 42), 16) // 马达重试开锁
          Data1301.motorPositionChange = parseInt(data.substring(42, 44), 16) //马达定位开关变化过程 0正常
          Data1301.hookChange = parseInt(data.substring(44, 46), 16) //锁钩开关变化过程 0正常
          Data1301.insertionSwitch = parseInt(data.substring(46, 48), 16) // 插入开关
          Data1301.lockSwitch = parseInt(data.substring(48, 50), 16) // 锁钩开关
          Data1301.motorPositionSecond = parseInt(data.substring(50, 52), 16) // 马达定位开关 0正常
          Data1301.startT = parseInt(data.substring(52, 54), 16) // 启动正常
          Data1301.startSim = parseInt(data.substring(54, 56), 16) // SIM卡读取正常 
    
          console.log(that.data.hasJurisdiction,'data12')
          if(that.data.hasJurisdiction){
            Data1301.netWorking = parseInt(data.substring(56, 58), 16) // NB测试结果
          }else{
            Data1301.netWorking = -1
          }
          Data1301.z = parseInt(data.substring(58, 60), 16) // END标志
        }

        if(isLinkLock) {
          Data1301.a = parseInt(data.substring(10, 12), 16)
          Data1301.b = parseInt(data.substring(12, 14), 16)
          Data1301.mac = data.substring(14, 26) // mac
          Data1301.KeyTrigger = parseInt(data.substring(26, 28), 16) //按键触发测试 
          Data1301.insertionSwitched = parseInt(data.substring(28, 30), 16) // 锁扣插入后，插入开关状态是否为1，
          Data1301.lockSwitched = parseInt(data.substring(30, 32), 16) // 锁扣插入后，锁钩状态是否为0
          Data1301.rfidOne = parseInt(data.substring(32, 34), 16) // RFID_1
          Data1301.rfidTwo = parseInt(data.substring(34, 36), 16) // RFID_2
          Data1301.runningTime = parseInt(data.substring(36, 38), 16) // 马达运行时长
          Data1301.locking = parseInt(data.substring(38, 40), 16) // 马达开锁错误码
          Data1301.k = parseInt(data.substring(40, 42), 16) // 马达开锁没弹开
          Data1301.l = parseInt(data.substring(42, 44), 16) // 马达重试开锁
          Data1301.insertionSwitch = parseInt(data.substring(44, 46), 16) // 插入开关
          Data1301.lockSwitch = parseInt(data.substring(46, 48), 16) // 锁钩开关
          Data1301.startT = parseInt(data.substring(48, 50), 16) // 启动正常
          Data1301.startSim = parseInt(data.substring(50, 52), 16) // SIM卡读取正常 
          console.log(that.data.hasJurisdiction,'data12')
          if(that.data.hasJurisdiction){
            Data1301.netWorking = parseInt(data.substring(52, 54), 16) // NB测试结果
          }else{
            Data1301.netWorking = -1
          }
          Data1301.z = parseInt(data.substring(54, 56), 16) // END标志
        }
        
        
        that.setData({
          Data1301: Data1301,
          step: 3
        })
        that.submit()
        console.log(that.data.Data1301, 'that.data.Data1301')
      }
    }, that)
    BLELocker.send1301Command(function (isSuccess) {
      if (isSuccess == false) {} else {}
    })

  },
  // 链条锁进入第二步
  clickLiantiao() {
    var that = this;
    if (that.data.errInfo) {
      console.log(that.data.errInfo, 'that.data.errInfo')
      that.setData({
        step3_ok: false,
      })
    }
    that.setData({
      step: 3,
    })
  },
  // 提交
  submit() {
    var that = this
    var err = 0;
    var errInfo = {};
    if (that.data.step == 2) {
      if (!that.data._Data1301.mac) {
        err++;
        errInfo.mac = "mac为空"
      }
      if (!that.data._Data1301.Version) {
        err++;
        errInfo.ver = "版本为空"
      }
      if (that.data._Data1301.voltage == 0) {
        err++;
        errInfo.voltage = "电压错误"
      }
      if (that.data._Data1301.memorizer != 0) {
        err++;
        errInfo.memorizer = "存储器错误"
      }
      if (that.data._Data1301.runningTime != 0) {
        err++;
        errInfo.runningTime = "马达运行超时"
      }
      if (that.data._Data1301.locking != 0) {
        err++;
        errInfo.locking = "马达开锁失败"
      }
      if (that.data._Data1301.insertionSwitch != 0) {
        err++;
        errInfo.insertionSwitch = "插入开关失败"
      }
      if (that.data._Data1301.lockSwitch != 0) {
        err++;
        errInfo.lockSwitch = "锁钩开关错误"
      }
      if(that.data._Data1301.motorPosition && that.data._Data1301.motorPosition != 0 &&  that.data._Data1301.motorPosition != -1) {
        err++;
        errInfo.motorPosition = "马达定位开关"
      }
      if (err != 0) {
        that.setData({
          step3_ok: false,
        });
        that.data.errInfo = errInfo;
        that.setInformation()

      } else {
        that.setData({
          step3_ok: true,
        });
        console.log('我没有报错，下一步')
      }
    }
    if (that.data.step == 3) {
      if (!that.data.Data1301.mac) {
        err++;
        errInfo.mac = "mac为空"
      }
      if (that.data.Data1301.KeyTrigger != 0 && that.data.Data1301.KeyTrigger != -1) {
        err++;
        errInfo.KeyTrigger = "按键触发测试"
      }
      if (that.data.Data1301.insertionSwitched != 0) {
        err++;
        errInfo.insertionSwitched = "锁扣插入开关状态"
      }
      if (that.data.Data1301.lockSwitched != 0) {
        err++;
        errInfo.lockSwitched = "锁扣插入锁钩状态"
      }
      if (that.data.Data1301.rfidOne != 0) {
        err++;
        errInfo.rfidOne = "rfid1"
      }
      if (that.data.Data1301.rfidTwo && that.data.Data1301.rfidTwo != 0 && that.data.Data1301.rfidTwo != -1) {
        err++;
        errInfo.rfidTwo = "rfid2"
      }
      if (that.data.Data1301.runningTime != 0) {
        err++;
        errInfo.runningTime = "马达运行时长"
      }
      if (that.data.Data1301.locking != 0) {
        err++;
        errInfo.locking = "马达开锁"
      }
      if (that.data.Data1301.insertionSwitch != 0) {
        err++;
        errInfo.insertionSwitch = "插入开关"
      }
   
     if (that.data.Data1301.lockSwitch != 0) {
        err++;
        errInfo.lockSwitch = "锁钩开关"
      }
      if(that.data.hasJurisdiction){
        if (that.data.Data1301.netWorking != 0) {
          err++;
          errInfo.netWorking = "NB状态"
        }
      }
      if (that.data.Data1301.startSim != 0) {
        err++;
        errInfo.startSim = "sim卡状态异常"
      }
      if (that.data.Data1301.startT != 0) {
        err++;
        errInfo.startT = "启动失败"
      }
      if(that.data.Data1301.k && that.data.Data1301.k != 0 && that.data.Data1301.k != -1) {
        err++;
        errInfo.k = "马达开锁是否弹开"
      }
      if (that.data.Data1301.motorPosition && that.data.Data1301.motorPosition != 0 && that.data.Data1301.motorPosition != -1) {
        err++;
        errInfo.matorPosition = "马达定位开关"
      }
      if (that.data.Data1301.motorPositionChange && that.data.Data1301.motorPositionChange != 0 && that.data.Data1301.motorPositionChange != -1) {
        err++;
        errInfo.motorPositionChange = "马达定位开关变化过程"
      }
      if (that.data.Data1301.hookChange && that.data.Data1301.hookChange != 0 && that.data.Data1301.hookChange != -1) {
        err++;
        errInfo.hookChange = "锁钩开关变化过程"
      }
      if (that.data.Data1301.motorPositionSecond && that.data.Data1301.motorPositionSecond != 0 && that.data.Data1301.motorPositionSecond != -1) {
        err++;
        errInfo.motorPositionSecond = "马达定位开关2"
      }

      if (err != 0) {
        that.setData({
          step3_ok: false,
          confirmOnly: true
        });
        that.data.errInfo = errInfo;
        that.setInformation()
      } else {
        that.setData({
          step3_ok: true,
        });
        that.setInformation()
        console.log('我没有报错')
        setTimeout(() => {
          wx.showToast({
            title: '我提交了',
          })
        }, 4000);
      }
    }
  },
  setInformation() {
    var that = this
    wx.showLoading({
      title: '正在提交检测',
      mask: true
    })
    let defaultStr = "{\"mac\":\"" +that.data.mac + "\"}"
    app.executeRequest(function (header) {
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + "/produceCheck/record",
        header: header,
        data: {
          _Data1301: that.data._Data1301 ? JSON.stringify(that.data._Data1301) : defaultStr,
          Data1301: that.data.Data1301 ? JSON.stringify(that.data.Data1301) : defaultStr,
          errInfo: that.data.errInfo ? JSON.stringify(that.data.errInfo) : '',
          startError: that.data.startError ? JSON.stringify(that.data.startError) : defaultStr
        },
        success: function (res) {
          getApp().hideLoading();
          if (res.data.result == 0) {
            if ((!that.data.errInfo || JSON.stringify(that.data.errInfo) == '"{}"') && JSON.stringify(that.data.startError.errReason) == '"{}"') {
              wx.showToast({
                title: '检测通过了',
                duration: 3000
              })
              setTimeout(() => {
                wx.navigateBack({
                  delta: 1
                })
              }, 3000);
            } else {
              wx.showToast({
                title: '未通过,已提交',
                icon: 'none'
              })
              that.setData({
                confirmOnly: true
              })
            }
          } else {
            wx.showToast({
              title: 'rst:网络异常',
              icon: 'none'
            })
          }
        },
        fail: function () {
          getApp().hideLoading();
          wx.showToast({
            title: 'fail:网络异常',
            icon: 'none'
          })
        },
        complete: function () {
          //断开蓝牙连接
          BLELocker.disconnect('produce303');
        }
      })
    });
  },
  // 检测不成功，提交

  //记录归位桩蓝牙连接错误日志
  recordBlueConnectError: function (errType, errDesc, tag) {
    let that = this;
    let nowTime = util.formatTime(new Date()) + '-----';

    var miniVer = ConstantData.CONSTATNT_DATA.MINI_VERSION;
    app.executeRequest(function (header) {
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease/error/bc',
        header: header,
        data: {
          homingPileBlueName: that.data.curBlueName, //归位桩的蓝牙名称
          phoneOs: '',
          phoneFactory: '',
          phoneType: '',
          weixinVer: miniVer, //微信版本号,最长45
          errType: parseInt(ConstantData.err_type.pruduce_test.replace(/[^0-9]/ig, '')), //错误类型
          errDesc: nowTime + ',' + errDesc + ',', //错误描述,最长545
          tag: tag && tag != 'undefined' ? tag : ''
        },
        success: function (res) {
          let netErr = app.handleRes(res, that);
          if (netErr) {
            return
          }
        },
        fail: function (res) {

        }
      })
    })
  },
})